﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_Reports_TrackStats : System.Web.UI.UserControl
{
	public BO.TracedAccount Track { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
		if (Track == null)
			return;
		if(!IsPostBack)
			LoadData();
    }

	public override void DataBind()
	{
		base.DataBind();

		if (IsPostBack)
		{
			LoadData();
		}
	}

	private void LoadData()
	{
		lblTitle.Text = Track.Name;
		lblUsrCount.Text = Track.FanNum.ToString();
		lblDate.Text = Track.StartDate.ToString();

		LoadChart();
		LoadImageUrl();
	}

	private void LoadImageUrl()
	{
		switch (Track.AccountType)
		{			
			case BO.TracedAccount.AccountTypes.Facebook:
                lblTitle.CssClass += " Icon FacebookIconSmall";
				//img.Attributes.ImageUrl = "/Images/SocialNetworks/FBIconBig.png";
				break;
			case BO.TracedAccount.AccountTypes.Twitter:
                lblTitle.CssClass += " Icon TwitterIconSmall";
				break;
			default:
				break;
		}
	}

	private void LoadChart()
	{
		if (Track.TraceStats == null || Track.TraceStats.Count == 0)
			return;

		var data = new List<string>();

		foreach (var item in Track.TraceStats)
		{
			data.Add(item.FanNum.ToString());
		}

		amLine.ExternalDataFileUrl = "/Service/websiteservice.asmx/TracedAccountTimeLine?traceID=" + Track.ID.ToString();
	}

	
}